package com.ideafactory.client.utils;

import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StrikethroughSpan;

import com.ideafactory.client.ybservice.APP;
import com.ideafactory.client.ybselfservice.R;

/**
 * Created by LiuShao on 2016/4/19.
 */
public class TextVUtils {
    /**
     * 关键字高亮显示
     * @param
     */
    public static SpannableString highlight(String message){
        SpannableString spannable = new SpannableString(message);
        if(message.contains(".")){
            int poitionLocation = message.indexOf(".");
            spannable.setSpan(new RelativeSizeSpan(1.5f), 0,poitionLocation, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            return spannable;
        }else{
            return null;
        }
    }

    /**
     * 放大文字大小
     * @param message
     * @return
     */
    public static SpannableString highScale(String message){
        SpannableString spannableString = new SpannableString(message);
        if(message.contains("x")){
            int position = message.indexOf("x");
            spannableString.setSpan(new ForegroundColorSpan(Color.BLACK), position,message.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  //设置前景色为洋红色
            spannableString.setSpan(new RelativeSizeSpan(1.3f),position,message.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return spannableString;
    }

    /**
     * 显示套餐价格
     * @param
     * @return
     */
    public static SpannableString setDeleteLine (String originPrice,String currentPrice,String unit){

        originPrice = AddPoint(originPrice);
        currentPrice = AddPoint(currentPrice);
        String priceString = "￥"+originPrice +"/￥"+ currentPrice+"/"+unit;
        int firstPosition = priceString.indexOf("/");
        int lastPosition = priceString.lastIndexOf("/");
        int lastPoint = priceString.lastIndexOf(".");

        SpannableString spannable = new SpannableString(priceString);
        spannable.setSpan(new StrikethroughSpan(),0, firstPosition, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannable.setSpan(new RelativeSizeSpan(1.6f),0,firstPosition,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannable.setSpan(new ForegroundColorSpan(APP.getAPP().getResources().getColor(R.color.for_ground_color)),0, firstPosition, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannable.setSpan(new RelativeSizeSpan(1.6f),firstPosition,lastPoint,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannable.setSpan(new RelativeSizeSpan(1.6f),lastPoint,lastPosition,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannable;
    }

    private static String AddPoint(String originPrice) {
        String msg;
        if(!originPrice.contains(".")){
            msg = originPrice+".";
        }else{
            msg = originPrice;
        }
        return msg;
    }

}
